import aes from './aes'
// import config from './config'
const setSession = (key, value) => {
  const val = process.env.NODE_ENV !== 'local'
    ? aes.Encrypt(JSON.stringify(value))
    : JSON.stringify(value)
    sessionStorage.setItem(key, val)
}
const getSession = (key) => {
  let value
  if (sessionStorage.getItem(key)) {
    const val = process.env.NODE_ENV !== 'local'
    ? JSON.parse(aes.Decrypt(sessionStorage.getItem(key)))
    : sessionStorage.getItem(key)
    value = JSON.parse(val)
  } else {
    return
  }
  return value
}
// 单个字段清除
const clearOneSession = (key) => {
  sessionStorage.removeItem(key)
}
// 全部删除
const clearAllSession = () => {
  sessionStorage.clear()
}
export default {
  set: setSession,
  get: getSession,
  clear: clearOneSession,
  clearAll: clearAllSession
}
